﻿#include <iostream>
using namespace std;
template <class T>
class Matrix
{
private:
	T** date_;
	int m_, n_;
public:
	Matrix()
	{
		date_ = NULL;
		m_ = 0;
		n_ = 0;
	}
	Matrix(int m, int n) :m_(m), n_(n)
	{
		date_ = new T * [m];
		for (int i = 0; i < m; i++)
		{
			date_[i] = new T[n]();
		}
	}
	~Matrix()
	{
		for (int i = 0; i < m_; i++)
		{
			delete[]date_[i];
		}
		delete[]date_;
	}
	void transport(T** date, int m, int n)
	{
		m_ = n; n_ = m;
		date_ = new T * [m_];
		for (int i = 0; i< m_; i++)
		{
			date_[i] = new T[n_];
		}
		for(int i=0;i<m;i++)
		{
			for (int j = 0; j < n; j++)
			{
				date_[j][i] = date[i][j];
			}
		}
	}
	Matrix(Matrix& c)
	{
		m_ = c.m_; n_ = c.n_;
		date_ = new T * [m_];
		for (int i = 0; i < m_; i++)
		{
			date_[i] = new T[n_];
			for (int j = 0; j < n_; j++)
			{
				date_[i][j] = c.date_[i][j];
			}
		}
	}
	void print()
	{
		for (int i = 0; i < m_; i++)
		{
			for (int j = 0; j < n_-1; j++)
			{
				cout << date_[i][j] << " ";
			}
			cout << date_[i][n_ - 1];
			cout << endl;
		}
	}
};
int main()
{
	int t, m, n;
	char ch;
	cin >> t;
	for (int k = 0; k < t; k++)
	{
		cin >> ch;
		getchar();//输入字母第二组输不进去一定要先把‘/n'弄掉
		if (ch == 'I')
		{
			cin >> m >> n;
			int** date = new int* [m];
			for (int i = 0; i < m; i++)
			{
				date[i] = new int[n];
			}
			for (int i = 0; i < m; i++)
			{
				for (int j = 0; j < n; j++)
				{
					cin >> date[i][j];
				}
			}
			Matrix<int> matrix(m, n);//娣诲姞<int>
			matrix.transport(date, m, n);
			matrix.print();
			for (int i = 0; i < m; i++)
			{
				delete[]date[i];
			}
			delete[]date;
		}
		else if (ch == 'D')
		{
			cin >> m >> n;
			double** date = new double* [m];
			for (int i = 0; i < m; i++)
			{
				date[i] = new double[n];
			}
			for (int i = 0; i < m; i++)
			{
				for (int j = 0; j < n; j++)
				{
					cin >> date[i][j];
				}
			}
			Matrix<double> matrix(m, n);
			matrix.transport(date, m, n);
			matrix.print();
			for (int i = 0; i < m; i++)
			{
				delete[]date[i];
			}
			delete[]date;
		}
		else
		{
			cin >> m >> n;
			char** date = new char* [m];
			for (int i = 0; i < m; i++)
			{
				date[i] = new char[n];
			}
			for (int i = 0; i < m; i++)
			{
				for (int j = 0; j < n; j++)
				{
					cin >> date[i][j];
				}
			}
			Matrix<char> matrix(m, n);
			matrix.transport(date, m, n);
			matrix.print();
			for (int i = 0; i < m; i++)
			{
				delete[]date[i];
			}
			delete[]date;
		}
	}
	return 0;
}
